#!/usr/bin/perl -w

use strict;
use diagnostics;

sub recurse($) {
    my($path) = @_;

    ## append a trailing / if it's not there
    $path .= '/' if($path !~ /\/$/);

    ## print the directory being searched
    print "DIR: ", $path," to ";

    $path =~ s/(\s)/\\$1/g;
    print $path,"\n";


    ## loop through the files contained in the directory
    for my $eachFile (glob("$path".'*')) {
        print "Item:", $eachFile;

        ## if the file is a directory
        if( -d "$eachFile") {
            print " - [DIR]\n";
            ## pass the directory to the routine ( recursion )
            recurse($eachFile);
        } else {

            ## print the file ... tabbed for readability
            if ($eachFile =~ m/.*txt$/) {
                print " - [TXT]\n";
            } elsif ($eachFile =~ m/.*doc$/) {
                print " - [DOC]\n";
            } elsif ($eachFile =~ m/.*htm$/) {
                print " - [HTM]\n";
            } elsif ($eachFile =~ m/.*html$/) {
                print " - [HTML]\n";
            } else {
                print "\n";
                qx{ mediainfo "$eachFile" > "$eachFile.txt" };
            }
        }
    }
}

## initial call ... $ARGV[0] is the first command line argument
recurse($ARGV[0]);

